/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.oper;

import java.time.LocalDate;

/**
 * <p>Project: app2022 - Switch4
 * <p>Powered by webrx On 2022-01-07 10:36:08
 *
* @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Switch4 {
    public static void main(String[] args) {
        int y = 2020;
        int m = 2;
        switch (m) {
            case 4, 6, 9, 11 -> System.out.printf("%d年%02d月有%02d天%n", y, m, 30);
            case 2 -> System.out.printf("%d年%02d月有%02d天%n", y, m, LocalDate.of(y, m, 1).isLeapYear() ? 29 : 28);
            default -> System.out.printf("%d年%02d月有%02d天%n", y, m, 31);
        }

    }

    public static void main2(String[] args) {
        int y = 2020;
        int m = 2;
        int days = switch (m) {
            case 4, 6, 9, 11 -> 30;
            //case 2 -> LocalDate.of(y, m, 1).isLeapYear() ? 29 : 28;
            case 2 -> {
                int t = 28;
                if (y % 400 == 0 || y % 4 == 0 && y % 100 != 0) {
                    t = 29;
                } else {
                    t = 28;
                }
                yield t; //相当于返回值 赋值给days
            }
            default -> 31;
        };
        System.out.printf("%d年%02d月有%02d天%n", y, m, days);
    }

}
